#include "mystrings.h" 



int main() {
	int count ;					
	char *str1, *str2 ;								/* variables to store strings */
	char  *line ;									/* buffer to read inputs */
	int choice;										/* variable to get the choice from user */
	char *temp  ;								 /* temporay ptr  print matching string */
	char c;
	char *ptr ;									 /* pointer to skip  leading spaces */



	/*allocating memory for the buffer */
	if ( (line =  (char *) malloc (MAXLINE * sizeof(char) ) )== NULL){
		fprintf(stderr," error in creating memory \n");
		exit(1);
	}

	while (1){

		printf (" 1.strncpy 2.strncat 3.strncmp 4.strrchr 5.strspn "
				"6.strcspn 7.strtok 8.strcasecmp  9.strstr\n");
		choice  = do_valid_no(line);
		switch  (choice){
			case 1:														/* calling strncpy */
				printf ("Enter the first string \n");
				do_get_string( line,&str1);
				printf (" str1 = %s \n",str1);

				printf (" enter the second string \n");
				do_get_string(line, &str2);
				printf (" str2 = %s \n",str2);
				printf ("enter number of charcter to copy :  ");
				count = do_valid_no(line);
				printf (" cont = %d \n",count);

				mystrncpy (str1,str2,count );
				printf (" the first sting :%s  \t Second %s \n",str1,str2);

				break ;

			case 2:														/* calling strncat */
				printf ("Enter the first string \n");
				do_get_string( line,&str1);

				printf (" string 1 = %s \n",str1);
				printf (" enter the second string \n");
				do_get_string(line, &str2);

				printf ("enter the number of charcter to copy :  ");
				count = do_valid_no(line);

				printf (" string 1 = %s \n",str1);
				printf (" enter the second string \n");
				mystrncat (str1,str2,count );
				printf (" the first sting :%s  \t Second %s \n",str1,str2);

				break ;

			case 3:													/*calling strncmp  */
				printf ("Enter the first string \n");
				do_get_string(line, &str1);

				printf (" enter the second string \n");
				do_get_string(line, &str2);
				printf ("enter the number of charcter to cmp :  ");

				count = do_valid_no(line);
				if ( (mystrncmp (str1,str2,count )) == 0)
					printf (" the strings are  same \n");
				else 
					printf (" The strings not are same \n");

				break ;

			case 4:													/* calling strrchr  */
				printf ("Enter the first string \n");
				do_get_string( line,&str1);

				printf("enter the character to search \n");
				if ((fgets (line, MAXLINE, stdin )) == NULL)
					exit (1);
				for ( ptr = line ; *ptr == ' '||*ptr == '\t'; ptr++)
					;

				c = *ptr ;
				temp = mystrrchr (str1,c );

				if ( temp == NULL)
					printf (" character is not found \n");
				else 
					printf (" character is found : %s \n",temp);

				break ;
			case 5:														/*calling strspn  */

				printf ("Enter the first string \n");
				do_get_string(line, &str1);
				printf (" enter the second string \n");
				do_get_string(line, &str2);

				count = mystrspn (str1,str2);
				printf  (" result :%d\n",count);

				break ;
			case 6:													/* calling strcspn */				
				printf ("Enter the first string \n");
				do_get_string(line, &str1);
				printf (" enter the second string \n");
				do_get_string(line, &str2);

				count = mystrcspn (str1,str2);
				printf  (" result :%d\n",count);

				break ;
			case 7:													/* calling strtok */
				printf ("Enter the first string \n");
				do_get_string(line, &str1);
				printf (" enter the second string \n");
				do_get_string( line,&str2);

				temp = mystrtok (str1,str2);
				while (temp ){
					if (*temp!= '\0') ;

					printf (" The tokens are :%s \n",temp);
					temp = mystrtok (NULL,str2);
				}

				break ;

			case 8:												   /* calling strcasecmp */

				printf ("Enter the first string \n");
				do_get_string(line ,&str1);
				printf (" enter the second string \n");
				do_get_string(line, &str2);
				if ( (mystrcasecmp (str1,str2 )) == 0)
					printf (" the strings are  same \n");
				else 
					printf (" The strings are same \n");
				break ;

			case 9:													/* calling strstr */
				printf ("Enter the first string \n");
				do_get_string(line, &str1);
				printf (" enter the second string \n");
				do_get_string(line, &str2);

				temp = mystrstr (str1,str2 );
				if (temp != NULL)
					printf (" string is found :%s \n",temp);
				else 
					printf  (" string is not found \n");

				break ;
			default:
				printf  (" ENTER VALID OPTION !!!!!!!\n");
				break;
		}

	} 

	free (line);									/* freeing all buffer and strings */
	free (str1);
	free (str2);
	return 0 ;
}
